<?php

namespace app\index\controller;
use think\Controller;
use think\Db;
use think\Session;
class Preowned extends Controller{
    /****
     * Class register                校园招聘添加
     * @$image[int]                  存储图片名称及路径
     * @$post['title']               招聘岗位id
     * @$post['image']               薪资
     * @$post['content']             发布人姓名
     * @$post['price']               招聘性别:0=女，1=男，2=不限制
     * @$post['classify_id']         工作时间
     * @$post['way']                 工作地点
     * @$post['degree_id']           学历:0=高中
     * @$post['addtime']             需求
     * @$post['headline_id']         校园头条id                   
     * @date                         2020/06/1 
     * @package application\index\controller\Preowned
    */
    public function preowned(){
        $post = input('post.');
        $img = str_replace('data:image/png;base64,', '', $post['image']);
        $image = ROOT_PATH . 'public' . DS . 'uploads'.DS.time().'.png';
        file_put_contents($image, base64_decode($img));
        $data = [
            'title'         =>$post['title'],
            'image'         =>$image,
            'content'       =>$post['content'],
            'price'         =>$post['price'],
            'classify_id'   =>$post['classify_id'],
            'way'           =>$post['way'],
            'degree_id'     =>$post['degree_id'],
            'addtime'       =>time(),
            'headline_id'   =>$post['headline_id'],
			'user_id'		=>$post['user_id']
        ];

        $headline_used = Db::name('headline_used')->insert($data);
        if($headline_used){
            $arr = [
               'state'     => 1,
               'message'  => "请求成功"
            ];
        }else{
            $arr = [
               'state'     => 0,
               'message'  => "请求失败！"
            ];
        }
        return json($arr);
    }
	/*二手商品分类*/
	public function classify(){
		$headline_used_type = Db::name('headline_used_type')->select();
             $arr = [
               'state'                  => 2,
               'headline_used_type'     =>$headline_used_type,
               'message'                => "分类请求成功"
            ];
            return json($arr);
	}
}
